#load packages
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.0 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(p8105.datasets)
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
data("rest_inspec")
nyc_restaurant = rest_inspec %>%
select(boro, cuisine_description, inspection_date, score, grade) %>%
filter(.data = ., boro == "MANHATTAN") %>%
na.omit()
#make a bar plot with count of different types of restaurant
nyc_restaurant %>%
count(cuisine_description) %>%
mutate(cuisine_description = fct_reorder(cuisine_description, n)) %>%
plot_ly(
x = ~cuisine_description, y = ~n, color = ~cuisine_description, type = "bar",
colors = "viridis"
)
#make a scatter plot with the score of different types of restaurant
nyc_restaurant %>%
mutate(cuisine_description = fct_reorder(cuisine_description, score)) %>%
plot_ly(y = ~score, color = ~cuisine_description, type = "box", colors = "viridis")